package com.kid.keep.dao.item;

import com.kid.keep.bo.CheckItemReportBO;
import com.kid.keep.po.CheckItemReport;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kid.keep.po.Child;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @Description CheckItemReport dao
 * @Author JOHN
 * @Create 2019-01-10
 * @Since 1.0.0
 */
@Repository
public class CheckItemReportRepository extends ServiceImpl<ICheckItemReportMapper, CheckItemReport> implements ICheckItemReportRepository {


    @Override
    public CheckItemReportBO findByChildIdAndStatus(Long childId, Integer status) {
        return this.baseMapper.findByChildIdAndStatus(childId, status);

    }

    @Override
    public int updateByChildIdAndStatus(CheckItemReport checkItemReport, Long childId, Integer status) {
        return this.baseMapper.update(checkItemReport, new UpdateWrapper<CheckItemReport>().lambda().eq(CheckItemReport::getChildId, childId).eq(CheckItemReport::getStatus, status));
    }

    @Override
    public CheckItemReportBO findByIdAndChildIdAndStatus(Long id, Long childId, Integer status) {
        return this.baseMapper.findByIdAndChildIdAndStatus(id, childId, status);
    }

    @Override
    public int countByChildIdAndStatus(Long childId,Integer status) {
        return this.count(new QueryWrapper<CheckItemReport>().lambda().eq(CheckItemReport::getChildId, childId).eq(CheckItemReport::getStatus, status));
    }

    @Override
    public CheckItemReportBO findByIdAndCreatorId(Long id, Long creatorId) {
        return this.baseMapper.findByIdAndCreatorId(id, creatorId);

    }

    @Override
    public List<CheckItemReportBO> listByDateAndCreatorIdAndStatus(Date startDate, Date endDate, Long creatorId, Integer status) {
        return this.baseMapper.listByDateAndCreatorIdAndStatus(startDate, endDate, creatorId, status);
    }

    @Override
    public List<CheckItemReportBO> listByDateAndCreatorIdAndChildIdAndStatus(Date startDate, Date endDate, Long childId, Long creatorId, Integer status) {
        return this.baseMapper.listByDateAndCreatorIdAndChildIdAndStatus(startDate, endDate, childId, creatorId, status);
    }

    @Override
    public int countCheckReport(Long creatorId, Integer status) {
        return this.count(new QueryWrapper<CheckItemReport>().lambda().eq(CheckItemReport::getCreatorId, creatorId).eq(CheckItemReport::getStatus, status));
    }


}


